package net.jarang.android.support.http;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.SimpleHttpConnectionManager;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.params.HttpClientParams;

public class HttpClientTemplate {
	public static HttpClient getClient(String host, int port, int connectionTimeout, int soTimeout) {
		HttpClientParams httpParams = new HttpClientParams();
		httpParams.setConnectionManagerClass(SimpleHttpConnectionManager.class);
		HttpClient client = new HttpClient(httpParams);
		client.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
		client.getHttpConnectionManager().getParams().setSoTimeout(soTimeout);
		client.getHostConfiguration().setHost(host, port);
		client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
		return client;
	}
	
	public static HttpClient getClient(int connectionTimeout, int soTimeout) {
		HttpClientParams httpParams = new HttpClientParams();
		httpParams.setConnectionManagerClass(SimpleHttpConnectionManager.class);
		HttpClient client = new HttpClient(httpParams);
		client.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
		client.getHttpConnectionManager().getParams().setSoTimeout(soTimeout);
		client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
		return client;
	}
}
